#include "LoadImageTask.h"
#include "debugger/Profiler.h"
#include "logger/Logger.h"

namespace easy2d {

	LoadImageTask::LoadImageTask(const char* filename, ITexture* texture, ISprite* sprite)
	{
		mSprite = sprite;
		mTexture = texture;
		mFileName = filename;

		if (mSprite)
			mSprite->texture(mTexture);
	}

	LoadImageTask::~LoadImageTask()
	{

	}

	bool LoadImageTask::onProcessInThread(void)
	{
		char szTmp[256];
		sprintf(szTmp, "load image %s", mFileName.c_str());
		FUNC_PF(szTmp);

		bool success = mImage.load(mFileName.c_str());
		if (!success) {
			LOGE("[ERROR] load image fail! filename=%s", mFileName.c_str());
		}

		return success;
	}

	bool LoadImageTask::onProcessInLogic(void)
	{
		mTexture->initialize(mImage);
		if (mSprite != NULL) {
			mSprite->initialize(mTexture->width(), mTexture->height());
		}
		return true;
	}


}	// namespace


